<?php
/********************************************************
 *
 * 此文件的作用:
 *		市场部后台控制器
 *
 * @copyright Copyright (c) 2008-2009
 * @author 刘昌功 lcg635@126.com
 *
 ********************************************************/
defined('APP_DIR') or die('404 Not Found');

FLEA::loadClass('Common_AdminAction');

class Controller_AdminMarket extends Common_AdminAction {
	/**
	 * 教员模型
	 *
	 * @var Model_Teacher
	 */
	var $modTeacher = null;
	
	/**
	 * 用户模型
	 *
	 * @var Model_User
	 */
	var $modUser = null;

	function __construct($ctlName)   {
		parent::__construct($ctlName);
		$this->modTeacher = FLEA::getSingleton('Model_Teacher');
		$this->modUser = FLEA::getSingleton('Model_User');
	}

	/*****************教员操作***********************************/

	function officialTeachersList() {
		$ui = FLEA::initWebControls();

		$viewData = $this->modTeacher->getTeachersByType(1, $this->saveGet('page'));
		$viewData['form']['teacher'] = $this->modTeacher->getForm('check');
		$viewData['form']['user'] = $this->modUser->getForm('register');
		$viewData['act'] = 'listteachers';
		$viewData['pagerData'] = $ui->control('pagernav', 'pagenav',
			array('pager'=>$viewData['pagerData'],'controller'=>'adminMarket', 'action'=>'officialTeachersList' ),
			true
		);
		
		$this->_out('market/officialTeachersList', $viewData);
	}
	
	function unVerifyTeachersList() {
		$ui = FLEA::initWebControls();
		
		$viewData = $this->modTeacher->getTeachersByType(0, $this->saveGet('page'));
		$viewData['form']['teacher'] = $this->modTeacher->getForm('check');
		$viewData['form']['user'] = $this->modUser->getForm('register');
		$viewData['act'] = 'SearTeacher' ;
		$viewData['pagerData'] = $ui->control('pagernav', 'pagenav',
			array('pager'=>$viewData['pagerData'],'controller'=>'adminMarket', 'action'=>'unVerifyTeachersList' ),
			true
		);
		$this->_out('market/unVerifyTeachersList', $viewData);	
	}
	
	function verifyFailTeachersList() {
		$ui = FLEA::initWebControls();
		
		$viewData = $this->modTeacher->getTeachersByType(2, $this->saveGet('page'));
		$viewData['form']['teacher'] = $this->modTeacher->getForm('check');
		$viewData['form']['user'] = $this->modUser->getForm('register');
		$viewData['act'] = 'SearTeacher' ;
		$viewData['pagerData'] = $ui->control('pagernav', 'pagenav',
			array('pager'=>$viewData['pagerData'],'controller'=>'adminMarket', 'action'=>'verifyFailTeachersList' ),
			true
		);
		$this->_out('market/verifyFailTeachersList', $viewData);		
	}
	
	function blacklistTeachersList() {
		$ui = FLEA::initWebControls();
		
		$viewData = $this->modTeacher->getTeachersByType(3, $this->saveGet('page'));
		$viewData['form']['teacher'] = $this->modTeacher->getForm('check');
		$viewData['form']['user'] = $this->modUser->getForm('register');
		$viewData['act'] = 'SearTeacher' ;
		$viewData['pagerData'] = $ui->control('pagernav', 'pagenav',
			array('pager'=>$viewData['pagerData'],'controller'=>'adminMarket', 'action'=>'blacklistTeachersList' ),
			true
		);
		$this->_out('market/verifyFailTeachersList', $viewData);
	}
	
	function unVerifyTeacher() {
		$this->modTeacher->unVerifyTeacher($this->saveGet('user_id'));
		redirect($_SERVER['HTTP_REFERER']);
	}
	
	function verifyTeacher() {
		$this->modTeacher->verifyTeacher($this->saveGet('user_id'));
		redirect($_SERVER['HTTP_REFERER']);
	}
	
	function blackListTeacher() {
		$this->modTeacher->blackListTeacher($this->saveGet('user_id'));
		redirect($_SERVER['HTTP_REFERER']);
	}
	
	function restoreTeacher() {
		$this->modTeacher->restoreTeacher($this->saveGet('user_id'));
		redirect($_SERVER['HTTP_REFERER']);
	}
	
	function deleteTeacher() {
		$this->modTeacher->delete($this->saveGet('user_id'));
		redirect($_SERVER['HTTP_REFERER']);
	}
	
	function dispTeacher() {
		$viewData = array('user' => $this->modUser->getUserInfo($this->saveGet('user_id'), 'teacher'));
		$this->_out('market/teacherDisp', $viewData);
	}

	function SearTeacher(){  //教员搜索
		$ui = FLEA::initWebControls();
		
		$viewData = $this->modTeacher->search($_POST, $this->saveGet('page'));
		$data = unserialize($_SESSION['sForm']);
		$viewData['form']['teacher'] = $this->modTeacher->getForm('check', $data);
		$viewData['form']['user'] = $this->modUser->getForm('register', $data);
		$viewData['act'] = 'SearTeacher';
		$viewData['type'] = $data['type'];
		$viewData['pagerData'] = $ui->control('pagernav', 'pagenav',
			array('pager'=>$viewData['pagerData'],'controller'=>'adminMarket', 'action'=>'SearTeacher' ),
			true
		);
		//$this->_out('market/unVerifyTeachersList',$viewData);
		$this->_out('market/officialTeachersList',$viewData);
	}

	/*****************教员操作结束*******************************/
	

	private function getSearchForm() {
		$form = array(
			'user' => $this->modUser->getForm('register'),
			'teacher' =>$this->modTeacher->getForm('check')
		);
		return $form;
	}
	
	/*****************家教业务操作*********************************/
	
	function listFamilyEdus() {
		$ui = FLEA::initWebControls();
		$_modFamilyEdu = FLEA::getSingleton('Model_FamilyEdu');
		$viewData = $_modFamilyEdu->getList($this->saveGet('page'));
		$viewData['pagerData'] = $ui->control('pagernav', 'pagenav',
			array('pager'=>$viewData['pagerData'],'controller'=>'adminMarket', 'action'=>'listFamilyEdus' ),
			true
		);
		$this->_out('market/familyEduList',$viewData);
	}

	function newFamilyEdu() {
		$_modFamilyEdu = FLEA::getSingleton('Model_FamilyEdu');
		$_modHouseholder = FLEA::getSingleton('Model_Householder');
		if ( $this->_isPOST() ) {
			$arr = array_chunk($_POST, 3, true);
			$householder = $arr[0];
			$_POST['householder_id'] = $_modHouseholder->insert($householder);
			$_modFamilyEdu->insert($_POST);
			redirect($this->_url('listFamilyEdus'));
		} else {
			$viewData['form'] = $_modFamilyEdu->getForm();
			$viewData['form']['householder'] = $_modHouseholder->getForm();
			$this->_out('market/newFamilyEdu',$viewData);
		}
	}
	
	function dispFamilyEdu() {
		$_modFamilyEdu = FLEA::getSingleton('Model_FamilyEdu');
		$viewData = $_modFamilyEdu->getInfo($this->saveGet('familyEdu_id'));
		$this->_out('market/familyEdudisp',$viewData);
	}

	/**************************文章管理**************************************/
	function listArticles() {//文章列表、所有文章，jancal 2008.10。18
		$_modNews = FLEA::getSingleton('Model_News');
		$ui = FLEA::initWebControls();
		$page = $this->saveGet('page');
		$viewData = $_modNews->getList('jj', $page, 15, true);
		$viewData['pagerData'] = $ui->control('pagernav', 'pagenav',
			array('pager'=>$viewData['pagerData'],'controller'=>'admin', 'action'=>'newsAll' ),
			true
		);
		$this->_out('news/newsList', $viewData);
	}

		function writeArticles() {//发布文章 jancal 2008.10.18
		$_modNews = FLEA::getSingleton('Model_News');
		if ( $this->_isPOST() ) {
			$_modNews->insert($_POST);
			$this->_throwRemind('添加成功', '新闻已经添加', null, $this->_url('newsAll'));
		} else {
			$viewData = array(
				'form' => $_modNews->getForm('new')
			);
			$this->_out('news/newsNew', $viewData);
		}
	}
	/**************************文章管理结束**************************************/
}
